//
//  ViewController.m
//  demo_fonts
//
//  Created by 李世达 on 2024/2/18.
//

#import "ViewController.h"
#import "TestViewCell.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *dataSource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"TestViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cellID"];
//    let screenScale = UIScreen.main.scale
    CGFloat scale = [UIScreen mainScreen].scale;
    CGRect nativeBounds = [UIScreen mainScreen].nativeBounds;
    CGFloat physicalWidth = nativeBounds.size.width;
    CGFloat physicalHeight = nativeBounds.size.height;
    NSLog(@"scale:%f,width:%f,height:%f",scale,physicalWidth,physicalHeight);
    //14 3x 1170*2532
    //xr 2x 828*1792
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 30;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TestViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellID" forIndexPath:indexPath];
    cell.mainTitle.text = [NSString stringWithFormat:@"主标题：大字体16号，第%ld组",indexPath.section];
    cell.mainTitle.font = [UIFont systemFontOfSize:16*scaleFont()];
    cell.subTitle.text = [NSString stringWithFormat:@"副标题：小字体12号，第%ld个",indexPath.row];
    cell.subTitle.font = [UIFont systemFontOfSize:12*scaleFont()];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 66;
}
// 定义一个内联函数
static inline float scaleFont(void) {
    CGFloat scale = [UIScreen mainScreen].scale;
    CGRect nativeBounds = [UIScreen mainScreen].nativeBounds;
    CGFloat realWidth = nativeBounds.size.width/scale;
    if (scale > 2.0) {
        return realWidth/390;
    }else {
        return 1;
    }
}
@end
